home *** CD-ROM | disk | FTP | other *** search
- Path: grimsel.zurich.ibm.com!usenet
- From: wgk@zurich.ibm.com (Keith Whittingham)
- Newsgroups: comp.lang.c
- Subject: Re: reversing a string
- Date: 10 Apr 1996 07:36:10 GMT
- Organization: IBM Research, ZRH
- Message-ID: <4kfoda$eue@grimsel.zurich.ibm.com>
- References: <4k6cjl$j8f@central.server.swt.edu> <4kb1s7$6eu@ibm32.perftech.com> <829058514snz@genesis.demon.co.uk> <4ke0b9$rk5@grimsel.zurich.ibm.com> <DpM3Kz.6t4@iquest.net>
- Reply-To: wgk@zurich.ibm.com
- NNTP-Posting-Host: pine.zurich.ibm.com
- X-Newsreader: IBM NewsReader/2 v1.00
-
- In <DpM3Kz.6t4@iquest.net>, dlmiller@iquest.net (Doug Miller) writes:
- >wgk@zurich.ibm.com (Keith Whittingham) wrote:
- >>Ole! (pronounced Spanishly but written 'olleh')
- >>
- >>Well here's a starter - no second variable but two recursive functions.
- >>Hopefully that can be reduced to one if my project can spare the time.
- >>(Note to manager: don't worry, just joking).
- >>
- >>#include <stdio.h>
- >>
- >>void RecRev2(char *s)
- >> {
- >> if(s[1])
- >> {
- >> if(s[2])
- >> {
- >> RecRev2(&s[1]);
- >> }
- >> s[0] ^= s[1]; s[1] ^= s[0]; s[0] ^= s[1];
- >> }
- >> }
- >>
- >>void RecRev1(char *s)
- >> {
- >> if(s && *s)
- >> {
- >> RecRev2(s);
- >> RecRev1(&s[1]);
- >> }
- >> }
- >>
- >>int main(int argc, char *argv)
- >> {
- >> char *s = "Hello";
- >> RecRev1(s);
- >> puts(s);
- >> return 0;
- >> }
- >>
- >This breaks if the string begins and ends with the same character.
-
- What are you talking about?!
-
- Keith
-
-
-